home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / source / snip9503 / mkdirs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-14  |  1.2 KB  |  56 lines

  1. /*
  2. **  MKDIRS.C - Function to build multi-level directories in a single call
  3. **
  4. **  Original Copyright 1993-94 by Bob Stout as part of
  5. **  the MicroFirm Function Library (MFL)
  6. **
  7. **  This subset version is hereby donated to the public domain.
  8. */
  9.  
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include <errno.h>
  14. #ifdef __TURBOC__
  15.  #include <dir.h>
  16. #else
  17.  #include <direct.h>
  18. #endif
  19.  
  20. int mkdirs(char *path)
  21. {
  22.       int retval;
  23.  
  24.       while (0 != (retval = mkdir(path)))
  25.       {
  26.             char subpath[FILENAME_MAX] = "", *delim;
  27.  
  28.             if (EACCES == errno)
  29.                   return retval;
  30.             if (NULL == (delim = strrchr(path, '\\')))
  31.                   return retval;
  32.             strncat(subpath, path, delim - path);     /* Appends NUL    */
  33.             mkdirs(subpath);
  34.       }
  35.       return retval;
  36. }
  37.  
  38. #ifdef TEST
  39.  
  40. main(int argc, char *argv[])
  41. {
  42.       if (2 > argc)
  43.       {
  44.             puts("Usage: MKDIRS pathname [...pathname]");
  45.             return -1;
  46.       }
  47.       while (--argc)
  48.       {
  49.             ++argv;
  50.             printf("mkdirs(%s) returned %d\n", *argv, mkdirs(*argv));
  51.       }
  52.       return 0;
  53. }
  54.  
  55. #endif /* TEST */
  56.